package com.beiye.drivertransport.adapter;

import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.frame.adapter.CommonAdapter;
import com.android.frame.adapter.ViewHolder;
import com.beiye.drivertransport.R;
import com.beiye.drivertransport.bean.HaveTestBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by ky on 2018/1/5.
 */

public class HaveTestAdapter  extends CommonAdapter<HaveTestBean.RowsBean> {
    private Context context;
    private List<HaveTestBean.RowsBean> mList;

    public HaveTestAdapter(Context context, List<HaveTestBean.RowsBean> mList, int itemLayoutId) {
        super(context, mList, itemLayoutId);
        this.context = context;
        this.mList=mList;
    }



    @Override
    public void convert(ViewHolder holder, HaveTestBean.RowsBean item, int positon) {
        TextView tv_havedate = holder.getView(R.id.tv_havetest);//日期
        TextView tv_qptName = holder.getView(R.id.tv_havetest1);//试卷种类名称
        TextView tv_total = holder.getView(R.id.tv_havetest3);//总分
        TextView tv_jigefenshu = holder.getView(R.id.tv_havetest11);//及格分数
        TextView tv_fenshu = holder.getView(R.id.tv_havetest4);//分数
        ImageView tv_jige = holder.getView(R.id.tv_havetest5);//及格
        TextView tv_fabu = holder.getView(R.id.tv_havetest2);//发布
        ImageView img_have = holder.getView(R.id.img_havetest);//是否补考
        long creationDate = mList.get(positon).getCreationDate();
        //mill为你龙类型的时间戳

       if(creationDate>0)
       {

           Date date=new Date(creationDate);
           String time="";
           try {
               //yyyy表示年MM表示月dd表示日
               //yyyy-MM-dd是日期的格式，比如2015-12-12如果你要得到2015年12月12日就换成yyyy年MM月dd日
               SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日");
               //进行格式化
               time=sdf.format(date);
           } catch (Exception e) {
               e.printStackTrace();
           }
           tv_havedate.setText("考试日期:"+time);
       }else{
           tv_havedate.setText("考试日期:"+"");
       }

        tv_qptName.setText(mList.get(positon).getQptName()+"—"+mList.get(positon).getQpName());
        tv_total.setText("试卷总分数:"+mList.get(positon).getTotalScore());
        tv_jigefenshu.setText("及格分:"+mList.get(positon).getPassScore());
        tv_fenshu.setText("试卷分数:"+mList.get(positon).getScore());
        int passMark = mList.get(positon).getPassMark();
        if(passMark==1)//及格
        {
            tv_jige.setImageResource(R.mipmap.jige);
        }else{//不及格
            tv_jige.setImageResource(R.mipmap.nojige);
        }

        int muMark = mList.get(positon).getMuMark();
        if(muMark==1)//补考
        {
            img_have.setImageResource(R.mipmap.bukaohavetest);
        }else if(muMark==0){
            img_have.setImageResource(R.mipmap.icon_07);
        }
        String paperSource = mList.get(positon).getPaperSource();
        if(paperSource==null)
        {
            tv_fabu.setText("企业发布");
        }else if(paperSource.equals("ad"))
        {
            tv_fabu.setText("区划发布");
        }else if(paperSource.equals("org"))
        {
            tv_fabu.setText("企业发布");
        }


    }
}
